package com.lt.basic.project.pojo.entity.admin.resource;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.lt.basic.project.common.uid.Id;
import com.lt.basic.project.common.util.StringUtils;
import com.lt.basic.project.pojo.validate.admin.resource.FileCreateValidate;
import com.lt.basic.project.pojo.validate.admin.resource.FileUpdateValidate;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
 * 文件管理(db_file)数据实体
 * @author ：LT
 * @Created in : 2023-08-25
 */

@Data
@ApiModel(value = "File对象", description = "文件管理(db_file)表")
public class File implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "主键")
    private Long id;

    /**
     * 文件名称
     */
    private String name;

    /**
     * 发布时间
     */
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date publishTime;

    /**
     * 是否有效
     */
    private Boolean isEffective;

    /**
     * 文件路径
     */
    private String url;

    /**
     * 类型
     */
    private Integer type;

    /**
     * 是否删除
     */
    private Boolean isDel;


    /**
    * 添加数据
    */
    public void create(FileCreateValidate createValidate) {
        setId(Id.getId());
        setName(createValidate.getName());
        setPublishTime(new Date());
        setIsEffective(true);
        setUrl(createValidate.getUrl());
        setType(createValidate.getType());
        setIsDel(false);
    }

    /**
    * 编辑数据
    */
    public void modify(FileUpdateValidate updateValidate) {
        if (StringUtils.isNotObj(updateValidate.getName())) {
            setName(updateValidate.getName());
        }
        if (StringUtils.isNotObj(updateValidate.getPublishTime())) {
            setPublishTime(updateValidate.getPublishTime());
        }
        if (StringUtils.isNotObj(updateValidate.getIsEffective())) {
            setIsEffective(updateValidate.getIsEffective());
        }
        if (StringUtils.isNotObj(updateValidate.getUrl())) {
            setUrl(updateValidate.getUrl());
        }
        if (StringUtils.isNotObj(updateValidate.getType())) {
            setType(updateValidate.getType());
        }
    }

}